package fuza.android.thetrafficsigns;

import java.util.ArrayList;
import java.util.HashMap;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemLongClickListener;

import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.app.SherlockListFragment;

import fuza.android.thetrafficsigns.help.LazyAdapter_Laws;


public class FragmentLaws extends SherlockListFragment {

	LazyAdapter_Laws adapter;
	Intent detail_laws;
	
	public static final String KEY_NAME_LAWS = "title";
	public static final String KEY_GAMBAR_LAWS = "img";
	
	
	public SherlockFragmentActivity getSherlockActivity(){
		return super.getSherlockActivity();
	}
	
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_laws, container,
				false);
		
		detail_laws = new Intent(getActivity(), DetailLaws.class);
		
		ListView ls = (ListView) view.findViewById(android.R.id.list);
		
		ArrayList<HashMap<String, String>> lawslist = new ArrayList<HashMap<String, String>>();
		
		for (int i = 0; i < 5; i++) {
			// creating new HashMap
			HashMap<String, String> map = new HashMap<String, String>();

			if (i == 0) {
				map.put(KEY_NAME_LAWS, "Every Road User");
				map.put(KEY_GAMBAR_LAWS, "roaduser");
			} else if (i == 1) {
				map.put(KEY_NAME_LAWS, "Each Driver");
				map.put(KEY_GAMBAR_LAWS, "eachdriver");
			}else if (i == 2) {
				map.put(KEY_NAME_LAWS, "Every Motorcyclist");
				map.put(KEY_GAMBAR_LAWS, "motorcyclist");
			}else if (i == 3) {
				map.put(KEY_NAME_LAWS, "Every Car Drivers");
				map.put(KEY_GAMBAR_LAWS, "cardriver");
			}else if (i == 4) {
				map.put(KEY_NAME_LAWS, "Every Public Transport");
				map.put(KEY_GAMBAR_LAWS, "publictransport");
			}
				

			lawslist.add(map);
		}
		
		adapter = new LazyAdapter_Laws(getActivity(), lawslist);
		ls.setAdapter(adapter);
		ls.setOnItemLongClickListener(new OnItemLongClickListener() {

			@Override
			public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				// TODO Auto-generated method stub
			
			Log.i("masuukdetaillaw", arg2+"");
				
				switch (arg2) {
				case 0:
					detail_laws.putExtra("id", "1");
					startActivity(detail_laws);
					break;

				case 1:
					detail_laws.putExtra("id", "2");
					startActivity(detail_laws);
					break;

				case 2:
					detail_laws.putExtra("id", "3");
					startActivity(detail_laws);
					break;
					
				case 3:
					detail_laws.putExtra("id", "4");
					startActivity(detail_laws);
					break;
					
				case 4:
					detail_laws.putExtra("id", "5");
					startActivity(detail_laws);
					break;
				}
				return false;
			}
		});
		
		return view;
	}

}
